<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\UserPoker;

/**
 * UserPokerSearch represents the model behind the search form about `app\models\UserPoker`.
 */
class UserPokerSearch extends UserPoker
{
    public $nick_name;
    public $agent_name;
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['poker_id', 'user_id', 'user_agent_id', 'score', 'in_score', 'out_score', 'end_score'], 'integer'],
            [['table_id', 'poker_name', 'ts','nick_name','agent_name'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = UserPoker::find();
        // $query->joinWith(['user_info']);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // $query->andFilterWhere([  
        //     'user_id' => $this->user_id,  
        // ]);  
  

        // grid filtering conditions
        $query->andFilterWhere([
            'poker_id' => $this->poker_id,
            'user_id' => $this->user_id,
            'user_agent_id' => $this->user_agent_id,
            'score' => $this->score,
            'in_score' => $this->in_score,
            'out_score' => $this->out_score,
            'ts' => $this->ts,
            'end_score' => $this->end_score,
        ]);

        $query->andFilterWhere(['like', 'table_id', $this->table_id])
            ->andFilterWhere(['like', 'poker_name', $this->poker_name]);
             // ->andFilterWhere(['like', 'user_info.name', $this->nick_name]) ;  //这个就是根据nickname参数进行搜索了，注意前面要加表名 

        return $dataProvider;
    }
}
